﻿using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using BE;


namespace DA
{
    public class daTrabajador
    {
        public static DataTable Obtener(beTrabajador oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_ConsultarTrabajador");
            sqlClient.AddInParameter(dbCmd, "@ID_Empleado", DbType.Int32, oBE.IDEmpleado);
            sqlClient.AddInParameter(dbCmd, "@ID_Reporte_Guardia", DbType.Int32, oBE.IDReporteGuardia);
            return sqlClient.ExecuteDataSet(dbCmd).Tables[0];
        }

        public static Int32 Registrar(beTrabajador oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_RegistrarTrabajador");

            sqlClient.AddInParameter(dbCmd, "@ID_Empleado", DbType.Int32, oBE.IDEmpleado);
            sqlClient.AddInParameter(dbCmd, "@ID_Reporte_Guardia", DbType.Int32, oBE.IDReporteGuardia);
            return Convert.ToInt32(sqlClient.ExecuteScalar(dbCmd));
        }

        public static Int32 Eliminar(beTrabajador oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_EliminarTrabajador");

            sqlClient.AddInParameter(dbCmd, "@ID_Empleado", DbType.Int32, oBE.IDEmpleado);
            sqlClient.AddInParameter(dbCmd, "@ID_Reporte_Guardia", DbType.Int32, oBE.IDReporteGuardia);

            return Convert.ToInt32(sqlClient.ExecuteScalar(dbCmd));
            //sqlClient.ExecuteNonQuery(dbCmd);
        }
    }
}